package org.moore.model;

import org.moore.utils.Data;

import java.awt.*;

// 消除物模型类
public class Block {
    // 可消除物图片
    private Image img;
    // 消除物的位置
    private int x;
    private int y;
    // 是否点击/选中
    private boolean isSelected;
    // 是否可消除
    private boolean isEliminated;
    // 方块类型
    private final int blockType;

    // 绘制自己的方法
    public void showMe(Graphics g) {
        // 使用g2d绘制以修复抗锯齿
        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.drawImage(img, x ,y, Data.W, Data.H, null);
        if (isSelected) {
            g2d.drawImage(Data.SELECT_IMAGE, x - 2, y - 2, Data.W + 5, Data.H + 5, null);
        }
    }

    public Block(int id, int row, int col, int blockType, Image img) {
        this.blockType = blockType;
        this.img = img;
        this.isSelected = false;
        this.isEliminated = false;
    }

    public Block(int blockType) {
        this.blockType = blockType;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void setSelected(boolean selected) {
        isSelected = selected;
    }

    public boolean isEliminated() {
        return isEliminated;
    }

    public void setEliminated(boolean eliminated) {
        isEliminated = eliminated;
    }

    public int getBlockType() {
        return blockType;
    }

}
